home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / CLEARERR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  578 b   |  24 lines

  1. /* clearerr.c */
  2. #include <stdio.h>
  3. void clearerr(FILE *infile);
  4. main()
  5. {
  6.     char file1[81];
  7.     FILE *infile;
  8.     long filesize;
  9.     printf ("Enter the name of an existing file: ");
  10.     gets(file1);
  11.                                             /* Open the file */
  12.     if ((infile = fopen(file1, "r")) == NULL)
  13.     {
  14.          printf ("fopen failed to open: %s\n", file1);
  15.          exit(0);
  16.     }
  17.     fprintf(infile, "Test..."); /* Try to read a line */
  18.     if (ferror(infile) != 0)    /* Check for the error */
  19.     {
  20.         printf("Error detected\n");
  21.         clearerr(infile);        /* Now clear the error */
  22.         rintf("Error cleared\n");
  23.     }
  24. }